package com.ruoyi.base.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.base.domain.vo.SysMessageInfoVo;
import com.ruoyi.base.domain.bo.SysMessageInfoBo;
import com.ruoyi.base.service.ISysMessageInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务消息通知
 *
 * @author kangyu
 * @date 2024-10-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/base/messageInfo")
public class SysMessageInfoController extends BaseController {

    private final ISysMessageInfoService iSysMessageInfoService;

    /**
     * 查询业务消息通知列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<SysMessageInfoVo> list(SysMessageInfoBo bo, PageQuery pageQuery) {
        return iSysMessageInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出业务消息通知列表
     */
    @SaCheckLogin
    @Log(title = "业务消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysMessageInfoBo bo, HttpServletResponse response) {
        List<SysMessageInfoVo> list = iSysMessageInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "业务消息通知", SysMessageInfoVo.class, response);
    }

    /**
     * 获取业务消息通知详细信息
     *
     * @param mId 主键
     */
    @SaCheckLogin
    @GetMapping("/{mId}")
    public R<SysMessageInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long mId) {
        return R.ok(iSysMessageInfoService.queryById(mId));
    }

    /**
     * 新增业务消息通知
     */
    @SaCheckLogin
    @Log(title = "业务消息通知", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysMessageInfoBo bo) {
        return toAjax(iSysMessageInfoService.insertByBo(bo));
    }

    /**
     * 修改业务消息通知
     */
    @SaCheckLogin
    @Log(title = "业务消息通知", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysMessageInfoBo bo) {
        return toAjax(iSysMessageInfoService.updateByBo(bo));
    }

    /**
     * 删除业务消息通知
     *
     * @param mIds 主键串
     */
    @SaCheckLogin
    @Log(title = "业务消息通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] mIds) {
        return toAjax(iSysMessageInfoService.deleteWithValidByIds(Arrays.asList(mIds), true));
    }
}
